/**
 * 矩形类，可移动
 * 属性：宽、高、横坐标、纵坐标、横向速度、纵向速度、dom对象
 */

class person{
    constructor(width,height,left,top,xSpeed,ySpeed,dom){
        this.width = width;
        this.height = height;
        this.left = left;
        this.top = top;
        this.xSpeed = xSpeed;
        this.ySpeed = ySpeed;
        this.dom = dom;
        this.render();

    }

    render(){
        this.dom.style.width = this.width + "px";
        this.dom.style.height = this.height + "px";
        this.dom.style.left = this.left + "px";
        this.dom.style.top = this.top + "px";
    }

/**
 * ttim单位为秒
 * @param {*} ttim 
 */
    move(ttim){
        const xDis = this.xSpeed * ttim;
        const yDis = this.ySpeed * ttim;

        this.left = this.left + xDis;
        this.top = this.top + yDis;

        if(this.onMove){
            this.onMove();
        }
        this.render();
    }
}